package com.ruoyi.cloudcourse.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.cloudcourse.mapper.FeatherChapterMapper;
import com.ruoyi.cloudcourse.domain.FeatherChapter;
import com.ruoyi.cloudcourse.service.IFeatherChapterService;
import com.ruoyi.common.core.text.Convert;

/**
 * 总章节Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-07-14
 */
@Service
public class FeatherChapterServiceImpl implements IFeatherChapterService 
{
    @Autowired
    private FeatherChapterMapper featherChapterMapper;

    /**
     * 查询总章节
     * 
     * @param chapterId 总章节ID
     * @return 总章节
     */
    @Override
    public FeatherChapter selectFeatherChapterById(Long chapterId)
    {
        return featherChapterMapper.selectFeatherChapterById(chapterId);
    }

    /**
     * 查询总章节列表
     * 
     * @param featherChapter 总章节
     * @return 总章节
     */
    @Override
    public List<FeatherChapter> selectFeatherChapterList(FeatherChapter featherChapter)
    {
        return featherChapterMapper.selectFeatherChapterList(featherChapter);
    }

    /**
     * 新增总章节
     * 
     * @param featherChapter 总章节
     * @return 结果
     */
    @Override
    public int insertFeatherChapter(FeatherChapter featherChapter)
    {
        return featherChapterMapper.insertFeatherChapter(featherChapter);
    }

    /**
     * 修改总章节
     * 
     * @param featherChapter 总章节
     * @return 结果
     */
    @Override
    public int updateFeatherChapter(FeatherChapter featherChapter)
    {
        return featherChapterMapper.updateFeatherChapter(featherChapter);
    }

    /**
     * 删除总章节对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteFeatherChapterByIds(String ids)
    {
        return featherChapterMapper.deleteFeatherChapterByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除总章节信息
     * 
     * @param chapterId 总章节ID
     * @return 结果
     */
    @Override
    public int deleteFeatherChapterById(Long chapterId)
    {
        return featherChapterMapper.deleteFeatherChapterById(chapterId);
    }

    /**
     * 查询总章节树列表
     * 
     * @return 所有总章节信息
     */
    @Override
    public List<Ztree> selectFeatherChapterTree()
    {
        List<FeatherChapter> featherChapterList = featherChapterMapper.selectFeatherChapterList(new FeatherChapter());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (FeatherChapter featherChapter : featherChapterList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(featherChapter.getChapterId());
            ztree.setpId(featherChapter.getFatherId());
            ztree.setName(featherChapter.getChapterName());
            ztree.setTitle(featherChapter.getChapterName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
